package Scene2;

import Picture.GameImage;
import Player.MusicPlayer;
import Scene1.Scene1;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.image.BufferedImage;

public  class PlantPanel extends JPanel {
    public int allEnd = 0;
    public volatile int pangbai = 0;
    public volatile int newBegin = 0;
    public volatile int bf = 0;

    Scene1 scene1 = new Scene1();
    public Scene2 scene2 = new Scene2();
    BufferedImage imgF = scene2.stackFont.pop();
    BufferedImage imgP = GameImage.get("/Picture/Scene2/bg.png");
    MusicPlayer b1 = new MusicPlayer("/music/b处理后/b1.mp3");
    MusicPlayer b2 = new MusicPlayer("/music/b处理后/b2.mp3");
    MusicPlayer b3 = new MusicPlayer("/music/b处理后/b3.mp3");
    MusicPlayer b4 = new MusicPlayer("/music/b处理后/b4.mp3");
    MusicPlayer b5 = new MusicPlayer("/music/b处理后/b5.mp3");
    MusicPlayer b6 = new MusicPlayer("/music/b处理后/b6.mp3");
    MusicPlayer b7 = new MusicPlayer("/music/b处理后/b7.mp3");
    MusicPlayer b8 = new MusicPlayer("/music/b处理后/b8.mp3");
    MusicPlayer b9 = new MusicPlayer("/music/b处理后/b9.mp3");
    MusicPlayer b10 = new MusicPlayer("/music/b处理后/b10.mp3");
    MusicPlayer b11= new MusicPlayer("/music/b处理后/b11.mp3");
    MusicPlayer b12= new MusicPlayer("/music/b处理后/b12.mp3");
    MusicPlayer b13 = new MusicPlayer("/music/b处理后/b13.mp3");
    MusicPlayer b14 = new MusicPlayer("/music/b处理后/b14.mp3");
    MusicPlayer b15 = new MusicPlayer("/music/b处理后/b15.mp3");
    MusicPlayer b16= new MusicPlayer("/music/b处理后/b16.mp3");
    MusicPlayer b17= new MusicPlayer("/music/b处理后/b17.mp3");
    MusicPlayer b18 = new MusicPlayer("/music/b处理后/b18.mp3");
    MusicPlayer b19 = new MusicPlayer("/music/b处理后/b19.mp3");
    MusicPlayer b20 = new MusicPlayer("/music/b处理后/b20.mp3");
    public PlantPanel(){
        new Thread(()->{
            while (true){

                if(bf==2){
                    b1.stop();

                }
                if(bf==3){
                    b2.stop();

                }
                if(bf==4){
                    b3.stop();

                }

                if(bf==5){
                    b4.stop();

                }
                if(bf==6){
                    b5.stop();

                }if(bf==7){
                    b6.stop();
                }if(bf==8){
                    b7.stop();
                }
                if(bf==9){
                    b8.stop();;
                }
                if(bf==10){
                    b9.stop();
                }
                if(bf==11){
                    b10.stop();
                }
                if(bf==12){
                    b11.stop();
                }
                if(bf==13){
                    b12.stop();
                }
                if(bf==14){
                    b13.stop();
                }if(bf==15){
                    b14.stop();
                }if(bf==16){
                    b15.stop();
                }if(bf==17){
                    b16.stop();
                }if(bf==18){
                    b17.stop();
                }if(bf==19){
                    b18.stop();
                }if(bf==20){
                    b19.stop();
                }
                if(bf==21){
                    b20.stop();
                }
            }
        }).start();
        new Thread(()->{
            while (true){
                if(bf==1){
                    b1.play();
                }
                if(bf==2){
                    b2.play();
                }
                if(bf==3){
                    b3.play();
                }
                if(bf==4){
                    b4.play();
                }
                if(bf==5){
                    b5.play();
                }
                if(bf==6){
                    b6.play();
                }if(bf==7){
                    b7.play();
                }if(bf==8){
                    b8.play();
                }if(bf==8){
                    b8.play();
                }
                if(bf==9){
                    b9.play();
                }
                if(bf==10){
                    b10.play();
                }
                if(bf==11){
                    b11.play();
                }
                if(bf==12){
                    b12.play();
                }
                if(bf==13){
                    b13.play();
                }
                if(bf==14){
                    b14.play();
                }if(bf==15){
                    b15.play();
                }if(bf==16){
                    b16.play();
                }if(bf==17){
                    b17.play();
                }if(bf==18){
                    b18.play();
                }if(bf==19){
                    b19.play();
                }if(bf==20){
                    b20.play();
                }
            }
        }).start();
        new Thread(()->{
            while (true) {
                if (pangbai == 1) {
                    pangbai = 0;
                    new MusicPlayer("/music/起始小精灵/a8.mp3").play();
                    bf = 1;
                    newBegin = 1;
                    repaint();
                }
            }
        }).start();

    }
    public void resize(JFrame frame){
        frame.setSize(1536,1110);
    }
    public void changeFont(){
        imgF = scene2.stackFont.pop();
        repaint();
    }
    public void changePic(){
        imgP = scene2.stackPic.pop();
        repaint();
    }
    
    public void paint(Graphics g) {
        super.paint(g);
        g.drawImage(imgP,0,0,null);
        if(newBegin==1) {
            g.drawImage(GameImage.get("/Picture/Scene2/npc.png"), -120, 450, null);
            g.drawImage(scene1.map.get("聊天框"), 250, 800, null);
            g.drawImage(scene1.map.get("箭头"), 1200, 970, null);
            g.drawImage(imgF, 360, 870, null);
        }



    }

}
